package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.FaultHandleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by shao-yikun on 2017/4/11.
 */

@Controller
@RequestMapping("/rds_faultHandleController")
public class FaultHandleController {

    @Resource
    private FaultHandleService faultHandleService;

    @RequestMapping("/getFaultHandle4DT")
    @ResponseBody
    public DTResponseDto getFaultHandle4DT(DTRequestDto dtRequestDto,
                                           Integer orgId,
                                           Integer maintenanceStatus,
                                           String actorIds) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = faultHandleService.getFaultHandle4DT(dtRequestDto, orgId, maintenanceStatus, actorIds);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getFaultHandle")
    @ResponseBody
    public JsonMsgDto getFaultHandle(Integer orgId,
                                     Integer maintenanceStatus,
                                     String actorIds,
                                     Integer mCount,
                                     Integer mySize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(faultHandleService.getFaultHandle(orgId, maintenanceStatus, actorIds, mCount, mySize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }


    @RequestMapping("/addMaintenanceContent")
    @ResponseBody
    public JsonMsgDto addMaintenanceContent(Integer maintenanceId, String maintenanceContent) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(faultHandleService.addMaintenanceContent(maintenanceId, maintenanceContent));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateMaintenance")
    @ResponseBody
    public JsonMsgDto updateMaintenance(MaintenanceDto maintenanceDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(faultHandleService.updateMaintenance(maintenanceDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMaintenanceByMaintenanceId")
    @ResponseBody
    public JsonMsgDto getMaintenanceByMaintenanceId(Integer maintenanceId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(faultHandleService.getMaintenanceByMaintenanceId(maintenanceId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping("/getReceiptByMaintenanceId")
    @ResponseBody
    public JsonMsgDto getReceiptByMaintenanceId(Integer maintenanceId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(faultHandleService.getReceiptByMaintenanceId(maintenanceId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

}
